<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分类页</title>
    <link rel="stylesheet" href="./css/style.css">
    <script src="./axios.js"></script>
</head>

<body>
    <div class="fix-title">
        <span>分类</span>
        <div class="text"><a href="#">搜索</a></div>
        <div class="text"><a href="#">搜索</a></div>
    </div>
    <ul class="cate-list">
    </ul>

    <script src="../个人设置/lib/axios.js"></script>
    <script>
        //设置根路径
        axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
        //发送请求获取到数据
        async function getData() {
            const { data } = await axios.get('/goods/cate')
            console.log(data)
            document.querySelector('.cate-list').innerHTML = data.data.map(item => `<li><a href="./list.html" id=${item.id}>${item.name}</a></li>`).join('')


            document.querySelector('.cate-list').addEventListener('click', function (e) {
                if (e.target.tagName === 'A') {

                    localStorage.setItem('id', `${e.target.id}`)
                }
            })
        }
        getData()
    </script>
</body>

</html>